//
//  ViewController.m
//  03-UIResponder
//
//  Created by 冀永金 on 16/7/18.
//  Copyright © 2016年 冀永金. All rights reserved.
//

#import "ViewController.h"
#import "TouchView.h"
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    TouchView *view = [[TouchView alloc]initWithFrame:CGRectMake(50, 50, 100, 50)];
    [self.view addSubview:view];
    view.backgroundColor = [UIColor blueColor];
    // 1.响应者链
    // 检测顺序：硬件-> Appdelegate -> UIApplication -> UIWindown -> UIViewController -> self.view -> TouchView
    
    // 相应顺序： TouchView -> self.view -> UIViewController -> UIWindown -> UIApplication -> Appdelegate -> null
    
    // 如果所有的响应者都无法响应该事件， 则这个事件都会被舍弃
    // 两种检测响应者的方法
    // 1.Category 实现 touchBegin 的方法
    // 2. nextReponder
    
    //
    // 例:
    // 1.响应者不要出边界, 出边界的响应者无法响应
    // 判断当前的点, 在谁的范围内
    BOOL a = [view pointInside:CGPointMake(10, 10) withEvent:nil];
    NSLog(@"%@", a  ? @"yes":@"no");
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    button.frame = CGRectMake(10, 210, 200, 50);
    button.backgroundColor = [UIColor greenColor];
    [view addSubview:button];
    [button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
    // button的点击方法如何实现
    
    // Do any additional setup after loading the view, typically from a nib.
}
- (void)buttonClick:(UIButton *)button {
    NSLog(@"dd");
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [super touchesBegan:touches withEvent:event];
    NSLog(@"11111:%@------%s",NSStringFromClass([self class]),__FUNCTION__);
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
